package cn.edu.hit.tendency;

import java.util.LinkedList;


/**
 * 固定长度队列
 *
 * @author gary
 */
public class TendencySourceQueue<E> extends LinkedList<E> {
    //队列长度
    private int limit;

    public TendencySourceQueue(int limit) {
        this.limit = limit;
    }

    /**
     * 获取限制大小
     *
     * @return
     */
    public int getLimit() {
        return limit;
    }

    @Override
    public boolean add(E e) {
        if (this.size() >= limit) {
            //如果超出长度,入队时,先出队
            this.poll();
        }
        return super.add(e);
    }
}
